<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择月份：">
              <el-date-picker v-model="form.MonthDate" type="month" placeholder="选择月" value-format="yyyy-MM" @change="reloadURL"></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      v-loading="loading"
      :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
      highlight-current-row
    >
      <el-table-column prop="班组名称" label="班组名称" align="center" width="150"></el-table-column>
      <el-table-column prop="班组长" label="班组长" align="center"></el-table-column>
      <el-table-column prop="日巡查道路数" label="日巡查道路数" align="center"></el-table-column>
      <el-table-column prop="道路总数" label="道路总数" align="center"></el-table-column>
      <el-table-column prop="巡查率" label="巡查率" align="center"></el-table-column>
      <el-table-column prop="巡查道路" label="巡查道路" align="center"></el-table-column>
      <el-table-column prop="道路巡查率" label="道路巡查率" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'

import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {

    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        // workerList: [],//车牌号列表
        // workerName: '',//人员名称
        // workerClientNO: '',//人员组号
        // alermTypeList: [{ label: '1分钟', value: '1' }, { label: '5分钟', value: '5' }, { label: '10分钟', value: '10' }, { label: '30分钟', value: '30' }],
        // alermTypeValue: '5',
        // StartDate: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        MonthDate: formatDate(new Date(), 'yyyy-MM'),
      },
      originalData: [],
      tableData: [],
      loading: false
    }
  },
  mounted () {
    this.getlistdata()
  },
  methods: {
    async getlistdata () {
      this.currentPage=1
      this.loading = true
      var url = 'Worker/GetCheckInfoMonthDetail?isLeader=true&month=' + this.form.MonthDate + '&ClientNo=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      // 原始数据
      this.tableData = data
      this.loading = false
    },
    // 导出Excel
    exportExcel () {
      let excelName = '班组长月平均作业百分比统计报表'
      const tHeader = ['班组名称', '班组长', '日巡查道路数', '道路总数', '巡查率', '巡查道路', '道路巡查率']
      const filterVal = ['班组名称', '班组长', '日巡查道路数', '道路总数', '巡查率', '巡查道路', '道路巡查率']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}
/* 弹出框 */
.el-dialog {
  background: #ccd8e7;
  padding: 0px 10px;
}
.el-dialog__title {
  color: #15428b;
  font-size: 16px;
  font-weight: 600;
}
.el-dialog__body {
  background: #dfe8f6;
  border: 1px solid #99bbe8;
}
.el-dialog__footer {
  padding: 10px 0px;
}
</style>